package com.ruoyi.web.controller.record;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.web.domain.ReservationRecord;
import com.ruoyi.web.service.IReservationRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约Controller
 * 
 * @author ruoyi
 * @date 2023-11-02
 */
@Controller
@RequestMapping("/execution/reservation")
public class ReservationRecordController extends BaseController
{
    private String prefix = "execution/reservation";

    @Autowired
    private IReservationRecordService reservationRecordService;

    @GetMapping()
    public String record()
    {
        return prefix + "/reservation";
    }

    /**
     * 查询预约列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReservationRecord reservationRecord)
    {
        startPage();
        reservationRecord.setCreateBy(ShiroUtils.getSysUser().getLoginName());
        List<ReservationRecord> list = reservationRecordService.selectReservationRecordList(reservationRecord);
        return getDataTable(list);
    }

    /**
     * 导出预约列表
     */
    @Log(title = "预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReservationRecord reservationRecord)
    {
        List<ReservationRecord> list = reservationRecordService.selectReservationRecordList(reservationRecord);
        ExcelUtil<ReservationRecord> util = new ExcelUtil<ReservationRecord>(ReservationRecord.class);
        return util.exportExcel(list, "预约数据");
    }

    /**
     * 新增预约
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预约
     */
    @Log(title = "预约", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReservationRecord reservationRecord)
    {
        return toAjax(reservationRecordService.insertReservationRecord(reservationRecord));
    }

    /**
     * 修改预约
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReservationRecord reservationRecord = reservationRecordService.selectReservationRecordById(id);
        mmap.put("reservationRecord", reservationRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存预约
     */
    @Log(title = "预约", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReservationRecord reservationRecord)
    {
        return toAjax(reservationRecordService.updateReservationRecord(reservationRecord));
    }

    /**
     * 删除预约
     */
    @Log(title = "预约", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reservationRecordService.deleteReservationRecordByIds(ids));
    }
}
